package com.cqtczh.qhd.driver;

import httptools.HttpJsonTool;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import tools.CrashHandler;
import tools.L;

import javabeen.UserInfoBeen;

import android.annotation.SuppressLint;
import android.app.Application;
import android.app.Service;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.util.Log;
import android.widget.Toast;

import cn.jpush.android.api.JPushInterface;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.GeofenceClient;
import com.baidu.location.LocationClient;
import com.cqtczh.qhd.driver.R;
import com.cqtczh.qhd.driver.api.GagApi;
import com.cqtczh.qhd.driver.model.LoginUserInfo;
import com.cqtczh.qhd.driver.utils.Base64Util;
import com.cqtczh.qhd.driver.utils.SPUtils;
import com.cqtczh.qhd.driver.utils.StringUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.util.PreferencesCookieStore;
import com.slidingmenu.lib.SlidingMenu;

public class AppContent extends Application {

	// 新版本app参数
	// 用户的ID
	/**
	 * 用户的ID
	 */
	public String userId;

	/**
	 * 车队推送消息时间监听
	 */
	public getCarTeamMessage messageCallback;

	public int orderLastTime = 300;
	public Handler orderLastTimecallback;
	// public OrderTimer orderTimer;
	// 当前页面是否已经打开 order activity
	public boolean isOrderActivity = false;
	// 现在订单的ID
	public String OrderId;
	public UserInfoBeen userInfoBeen; // 用户的信息
	// 用来保存用户信息验证的数据
	// 数据信息

	// 用来保存用户信息验证的数据
	// 新版本app参数

	// -----------------------------------------------------------
	public static final int LOCATION_TIME = 60000;
	public LocationClient mLocationClient;
	public GeofenceClient mGeofenceClient;
	public MyLocationListener mMyLocationListener;
	public Vibrator mVibrator;
	private static Context sContext;
	public String adrr = "点击获取当前位置";
	public double longitude = 0.0;
	public double latitude = 0.0;
	public BDLocation localLocation = null;
	private HttpUtils http = new HttpUtils();
	private RequestParams params;

	public Handler handler, pusHandler;
	public boolean DriverIsOnline = false;
	public static Gson gson = new Gson();
	public static String PhoneNO = null;
	public String channelId = null;
	public final  String  messagepushuserId = "null";
	public String user_phone_no = null;
	public GetPushMessage callback;
	/**
	 * 车队删除人员信息
	 */
	public GetCarTeamDelete deletecallback;
	/**
	 * 公司车队邀请信息
	 */
	public CompleteCarTeam completeCallback;

	/**
	 * 菜单接口
	 */
	@SuppressLint("NewApi")
	public menuCEHD mCehd;

	public boolean new_home_activity_data_has_change = false;
	public String OrderActivity_data_change_poition = "";
	public boolean OrderActivity_data_has_change = false;
	public boolean Have_Order_Complete = false;
	/**
	 * 新订单的声音
	 */
	private boolean SounComplete = false;
	/**
	 * 订单新的信息
	 * 
	 */
	private boolean ordermessageComplete = false;

	/**
	 * 但有新订单来的时候要求所有订单更改
	 */
	public boolean New_Order_Push = false;

	/**
	 * 司机信息验证通过接口
	 */
	private userInfoCheck userinfocallback;

	/**
	 * 
	 */
	private boolean upload_baidu=true;
	
	public static Context getContext() {
		return sContext;
	}

	/**
	 * 设置菜单
	 */
	public SlidingMenu menu;
	/**
	 * 新订单声音
	 */
	public SoundPool soundPool;
	public int soud_id;

	/**
	 * 订单语音声音
	 */
	public SoundPool ordermessagePool;
	public int ordermessage_id;
	/**
	 * 订单新的消息声音
	 */
	public SoundPool order_new_info_Pool;
	public int order_new_info_id;
	public boolean order_new_info_flag;
	/**
	 * 订单完成声音
	 */
	public SoundPool order_complete_Pool;
	public int order_complete_id;
	public boolean order_complete_Pool_flag;
	/**
	 * 订单取消声音
	 */
	public SoundPool order_remove_Pool;
	public int order_remove_Pool_id;
	public boolean order_remove_Pool_flag;

	private driverVerificationMessage driverVerificationCallback;

	public static PreferencesCookieStore preferencesCookieStore;

	public static PreferencesCookieStore getPreferencesCookieStore() {
		return preferencesCookieStore;
	}

	public static void setPreferencesCookieStore(
			PreferencesCookieStore preferencesCookieStore) {
		AppContent.preferencesCookieStore = preferencesCookieStore;
	}

	public static void setPhoneNO(String phoneno) {
		AppContent.PhoneNO = phoneno;
	}

	public String jPushRegistrationID;

	public void onCreate() {
		super.onCreate(); // 在使用 SDK 各组间之前初始化 context信息，传入ApplicationContext
		sContext = getApplicationContext();
		JPushInterface.init(getApplicationContext());
		JPushInterface.setDebugMode(true);
		// FrontiaApplication.initFrontiaApplication(getApplicationContext());
	
		 CrashHandler crashHandler = CrashHandler.getInstance();
//		 crashHandler.init(getApplicationContext());
		mLocationClient = new LocationClient(this.getApplicationContext());
		mMyLocationListener = new MyLocationListener();
		mLocationClient.registerLocationListener(mMyLocationListener);
		mGeofenceClient = new GeofenceClient(getApplicationContext());
		mVibrator = (Vibrator) getApplicationContext().getSystemService(
				Service.VIBRATOR_SERVICE);
		// SDKInitializer.initialize(sContext);
		// 初始化声音
		IniSound();
		channelId = JPushInterface.getRegistrationID(getApplicationContext());
		// 建立订单剩余时间的广播接收者
		// IniOrderLastTimeReceiver();
	}

	public void IniSound() {
		soundPool = new SoundPool(2, AudioManager.STREAM_RING, 0);
		soud_id = soundPool.load(this, R.raw.mssage, 1);
		soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {

			@Override
			public void onLoadComplete(SoundPool sound, int arg1, int arg2) {
				// TODO Auto-generated method stub
				SounComplete = true;
			}
		});

		ordermessagePool = new SoundPool(2, AudioManager.STREAM_RING, 0);
		ordermessage_id = ordermessagePool.load(this, R.raw.ordernewmessage, 1);
		ordermessagePool
				.setOnLoadCompleteListener(new OnLoadCompleteListener() {

					@Override
					public void onLoadComplete(SoundPool arg0, int arg1,
							int arg2) {
						// TODO Auto-generated method stub
						// L.v("出来", "onLoadComplete");
						ordermessageComplete = true;
					}
				});
		// -*
		order_new_info_Pool = new SoundPool(2, AudioManager.STREAM_RING, 0);
		order_new_info_id = order_new_info_Pool.load(this, R.raw.ordernewinfo,
				1);
		order_new_info_Pool
				.setOnLoadCompleteListener(new OnLoadCompleteListener() {

					@Override
					public void onLoadComplete(SoundPool arg0, int arg1,
							int arg2) {
						// TODO Auto-generated method stub
						// L.v("出来", "onLoadComplete");
						order_new_info_flag = true;
					}
				});
		// -*
		order_complete_Pool = new SoundPool(2, AudioManager.STREAM_RING, 0);
		order_complete_id = order_complete_Pool.load(this, R.raw.ordercomplete,
				1);
		order_complete_Pool
				.setOnLoadCompleteListener(new OnLoadCompleteListener() {

					@Override
					public void onLoadComplete(SoundPool arg0, int arg1,
							int arg2) {
						// TODO Auto-generated method stub
						// L.v("出来", "onLoadComplete");
						order_complete_Pool_flag = true;
					}
				});
		// -*
		order_remove_Pool = new SoundPool(2, AudioManager.STREAM_RING, 0);
		order_remove_Pool_id = order_remove_Pool.load(this, R.raw.orderremove,
				1);
		order_remove_Pool
				.setOnLoadCompleteListener(new OnLoadCompleteListener() {

					@Override
					public void onLoadComplete(SoundPool arg0, int arg1,
							int arg2) {
						// TODO Auto-generated method stub
						// L.v("出来", "onLoadComplete");
						order_remove_Pool_flag = true;
					}
				});

	}

	public void PlaySound(int type) {
		if (type == 1) {

			if (SounComplete) {
				AudioManager amAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
				float audioMaxVolum = amAudioManager
						.getStreamMaxVolume(AudioManager.STREAM_RING);
				soundPool.play(soud_id, audioMaxVolum, audioMaxVolum, 0, 0, 1);
			} else {
				Toast.makeText(this, "音乐控件还未准备好！！！2秒就好", Toast.LENGTH_LONG)
						.show();
			}
		}
		if (type == 2) {
			if (ordermessageComplete) {
				AudioManager amAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
				float audioMaxVolum = amAudioManager
						.getStreamMaxVolume(AudioManager.STREAM_RING);
				L.v("----------------", "--------------------------");
				L.v("audioMaxVolum", "" + audioMaxVolum);
				L.v("----------------", "--------------------------");
				ordermessagePool.play(ordermessage_id, audioMaxVolum,
						audioMaxVolum, 0, 0, 1);
			} else {
				Toast.makeText(this, "音乐控件还未准备好！！！2秒就好", Toast.LENGTH_SHORT)
						.show();
			}
		}
		if (type == 3) {
			if (order_new_info_flag) {
				AudioManager amAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
				float audioMaxVolum = amAudioManager
						.getStreamMaxVolume(AudioManager.STREAM_RING);
				L.v("----------------", "--------------------------");
				L.v("audioMaxVolum", "" + audioMaxVolum);
				L.v("----------------", "--------------------------");
				order_new_info_Pool.play(order_new_info_id, audioMaxVolum,
						audioMaxVolum, 0, 0, 1);
			} else {
				Toast.makeText(this, "音乐控件还未准备好！！！2秒就好", Toast.LENGTH_SHORT)
						.show();
			}
		}
		if (type == 4) {
			if (order_complete_Pool_flag) {
				AudioManager amAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
				float audioMaxVolum = amAudioManager
						.getStreamMaxVolume(AudioManager.STREAM_RING);
				L.v("----------------", "--------------------------");
				L.v("audioMaxVolum", "" + audioMaxVolum);
				L.v("----------------", "--------------------------");
				order_complete_Pool.play(order_complete_id, audioMaxVolum,
						audioMaxVolum, 0, 0, 1);
			} else {
				Toast.makeText(this, "音乐控件还未准备好！！！2秒就好", Toast.LENGTH_SHORT)
						.show();
			}
		}
		if (type == 5) {
			if (order_remove_Pool_flag) {
				AudioManager amAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
				float audioMaxVolum = amAudioManager
						.getStreamMaxVolume(AudioManager.STREAM_RING);
				L.v("----------------", "--------------------------");
				L.v("audioMaxVolum", "" + audioMaxVolum);
				L.v("----------------", "--------------------------");
				order_remove_Pool.play(order_remove_Pool_id, audioMaxVolum,
						audioMaxVolum, 0, 0, 1);
			} else {
				Toast.makeText(this, "音乐控件还未准备好！！！2秒就好", Toast.LENGTH_SHORT)
						.show();
			}
		}
	}

	public void GetGpsAddressCallBack(final GetGpsAddress callback) {
		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				callback.GetAddress((String) msg.obj);
				super.handleMessage(msg);
			}
		};
	}

	/**
	 * 
	 * @author 陈修园 车队推送接口
	 */
	public interface getCarTeamMessage {
		public void carTeamMessage(String message, String invitation,
				String motorcadeid);
	}

	/**
	 * 
	 * @author 陈修园 设置车队推送信息监听
	 */
	public void setCarTeamMessageLister(getCarTeamMessage geCarTeamMessage) {
		this.messageCallback = geCarTeamMessage;
	}

	/**
	 * 
	 * @author 陈修园 当车队消息来的时候
	 */
	public void setCarteamPushMessage(boolean flag, String message,
			String invitation, String motorcadeid) {
		if (messageCallback != null) {
			messageCallback.carTeamMessage(message, invitation, motorcadeid);

		}
	}

	/**
	 * 
	 * @author 陈修园 司机个人信息验证消息
	 */
	public interface driverVerificationMessage {
		public void verification(String message);
	}

	/**
	 * 
	 * @author 陈修园 个人消息监听设置消息监听
	 */
	public void setdriverVerificationMessage(driverVerificationMessage callback) {
		this.driverVerificationCallback = callback;
	}

	/**
	 * 
	 * @author 陈修园 推送消息司机身份验证来的时候
	 */
	public void ondriverVerification(String message) {
		if (driverVerificationCallback != null) {
			driverVerificationCallback.verification(message);
		}
	}

	public interface GetGpsAddress {
		public void GetAddress(String address);
	}

	public interface GetPushMessage {
		public void GetMessage(String msg, String CarTeamLeader,
				String CarTeamId);
	}

	public interface GetCarTeamDelete {
		public void GetDeleteMessage(String msg, String CarTeamLeader,
				String CarTeamId);
	}

	/**
	 * 
	 * @author 陈修园 公司的名称 公司车队ID 和信息
	 */
	public interface CompleteCarTeam {
		public void GetCompleteCarTeam(String msg, String CarTeamID,
				String CompleteName);

	}

	/**
	 * 
	 * @author luck 获得订单的剩余时间
	 */
	// public interface GetOrderLastTime{
	// public void GetTime(int time);
	// }
	//
	public void setGetOrderLastTimeCallBack(Handler callback) {
		this.orderLastTimecallback = callback;
	}

	public void SetPushMessage(boolean flag, String msg, String CatTeamLeader,
			String CatTeamId) {
		if (flag) {
			// pusHandler.sendMessage(msg);
			// pusHandler.sendEmptyMessage(1);
			if (callback != null) {
				L.v("直接运行了------------", "----------------");
				new_home_activity_data_has_change = true;
				OrderActivity_data_has_change = true;
				OrderActivity_data_change_poition = "1";
				callback.GetMessage(msg, CatTeamLeader, CatTeamId);
			} else {
				L.v("callback", "空");
			}

		}
	}

	public void CompleteCarTeamMessage(String message, String CarTeamID,
			String CompleteName) {
		if (completeCallback != null) {
			completeCallback.GetCompleteCarTeam(message, CarTeamID,
					CompleteName);
		}
	}

	public void SetCompleteCarTeamMessage(CompleteCarTeam completeCallback) {
		this.completeCallback = completeCallback;
	}

	public void CarDeletMessage(boolean flag, String msg, String CatTeamLeader,
			String CatTeamId) {
		if (deletecallback != null) {
			deletecallback.GetDeleteMessage(msg, CatTeamLeader, CatTeamId);
		}

	}

	/**
	 * 
	 * @Title: SetGetCarTeamDelete
	 * @Description: TODO(设置车队删除的callback)
	 * @param 参数说明
	 * @return void 返回类型
	 * @throws
	 */
	public void SetGetCarTeamDelete(GetCarTeamDelete callback) {
		this.deletecallback = callback;
	}

	public void SetPushMessageLister(GetPushMessage call) {
		this.callback = call;
	}

	/**
	 * 实现实位回调监听
	 */
	public class MyLocationListener implements BDLocationListener {

		@Override
		public void onReceiveLocation(BDLocation location) {
			// 检查百度推送是否开启
			// checkBaiduPushMessage();
			localLocation = location;
			adrr = location.getAddrStr();
			Message msg = Message.obtain();
			msg.obj = location.getAddrStr();
			handler.sendMessage(msg);
			if (latitude != location.getLatitude()
					|| longitude != location.getLongitude()) {
				if (!(StringUtils.isEmpty(userId))) {
					if (upload_baidu) {
						upBaiDuPussh();
						upload_baidu=false;
					}
				}
			}
			L.v("AppContent", "DriverIsOnline=" + DriverIsOnline);

			add(location.getLatitude(), location.getLongitude(),
					location.getAddrStr(), "司机", channelId, messagepushuserId);

			longitude = location.getLongitude();
			latitude = location.getLatitude();
		
		}

	}

	// /**
	// * 显示请求字符串
	// *
	// * @param str
	// */
	// public void logMsg(String str) {
	// try {
	// // if (mLocationResult != null)
	// // mLocationResult.setText(str);
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// }

	/**
	 * 
	 * @Title: add 上传数据online offline
	 * @Description: TODO(上传数据 online offline)
	 * @param @param d
	 * @param @param e
	 * @param @param addr
	 * @param @param type 上线还是下线
	 * @param @param channelId
	 * @param @param messagepushuserId 参数说明
	 * @return void 返回类型
	 * @throws
	 */
	public void add(double d, double e, String addr, String type,
			String channelId, String messagepushuserId) {
		String URL = "";
		L.v("AppContent", "上传");
		L.v("ConnectionState","--->" +JPushInterface.getConnectionState(getApplicationContext()));
		L.v("isPushStopped","-->"+ JPushInterface.isPushStopped(getApplicationContext()));
		if (!JPushInterface.getConnectionState(getApplicationContext())) {
			JPushInterface.init(getApplicationContext());
			JPushInterface.resumePush(getApplicationContext());
		}
		if (JPushInterface.isPushStopped(getApplicationContext())) {
			JPushInterface.resumePush(getApplicationContext());
		}
		Map<String, Object> dataMap = new HashMap<String, Object>();
		String lat = Double.toString(d);
		String longitud = Double.toString(e);
		dataMap.put("latitude", lat);
		dataMap.put("longitude", longitud);
		// dataMap.put("title", addr);
		dataMap.put("address", addr);
		// dataMap.put("userType", type);
		dataMap.put("userId", userId);
		dataMap.put("userId", messagepushuserId);
		dataMap.put("channelId", channelId);
		dataMap.put("carownerId", userId);

		if (DriverIsOnline) {
			URL = GagApi.ON_LINE;
			L.v("是否在线：", "on");
			// Toast.makeText(this, "", Toast.LENGTH_LONG).show();
			// this
			HttpJsonTool httpJsonTool = new HttpJsonTool(this);
			httpJsonTool.SetOnLister(new Handler() {
				@Override
				public void handleMessage(Message msg) {
					// TODO Auto-generated method stub
					super.handleMessage(msg);
					if (msg.what == 1) {
						L.v("上传成功", (String) msg.obj);
					} else {
						if (msg.obj != null) {
							L.v("上传失败", (String) msg.obj);
						}

					}
				}
			});
			httpJsonTool.StartWork(dataMap, URL, null, null);

		} else {

		}
		if (type.equals("off")) {
			URL = GagApi.OFF_LINE;
			L.v("司机点击下线了", "司机点击下线了");

			HttpJsonTool httpJsonTool = new HttpJsonTool(this);
			httpJsonTool.SetOnLister(new Handler() {
				@Override
				public void handleMessage(Message msg) {
					// TODO Auto-generated method stub
					super.handleMessage(msg);
					if (msg.what == 1) {
						L.v("上传成功", (String) msg.obj);
					} else {
						if (msg.obj != null) {
							L.v("上传失败", (String) msg.obj);
						}

					}
				}
			});
			httpJsonTool.StartWork(dataMap, URL, null, null);

		}
	}

	/**
	 * 高精度地理围栏回调
	 * 
	 * @author jpren
	 * 
	 */

	/**
	 * 
	 * 接受订单的广播最后时间
	 * 
	 */
	public void IniOrderLastTimeReceiver(int listid) {
		// new Thread(new OrderTimer(listid)).start();
	}

	/**
	 * 
	 * @author 陈修园 设置菜单弹出的接口
	 */
	public interface menuCEHD {
		// 显示菜单
		public void showMenu();

		// disable菜单显示
		public void disableTouchShowMenu();

		// enable 菜单显示
		public void enabelTouchShowMenu();
	}

	/**
	 * 
	 * @Title: setMenuLiseter
	 * @Description: TODO(设置菜单点击弹出事件)
	 * @param @param menu 参数说明
	 * @return void 返回类型
	 * @throws
	 */
	public void setMenuLiseter(menuCEHD menu) {
		this.mCehd = menu;
	}

	/**
	 * 
	 * @Title: menuCEHDonChange
	 * @Description: TODO(设置菜单点击弹出回调事件)
	 * @param 参数说明
	 * @return void 返回类型
	 * @throws
	 */
	public void menuCEHDonChange() {
		if (mCehd != null) {
			mCehd.showMenu();
		}
	}

	/**
	 * 
	 * @Title: startMenuShowFunction
	 * @Description: TODO(启动菜单手势)
	 * @param 参数说明
	 * @return void 返回类型
	 * @throws
	 */
	public void startMenuShowFunction() {
		if (mCehd != null) {
			mCehd.enabelTouchShowMenu();
		}
	}

	/**
	 * 
	 * @Title: stopMenuShowFunction
	 * @Description: TODO(停止手势功能)
	 * @param 参数说明
	 * @return void 返回类型
	 * @throws
	 */
	public void stopMenuShowFunction() {
		if (mCehd != null) {
			mCehd.disableTouchShowMenu();
		}
	}

	/**
	 * 
	 * @Title: userCheckComplete
	 * @Description: TODO(司机信息检查完成)
	 * @param 参数说明
	 * @return void 返回类型
	 * @throws
	 */
	public void userCheckComplete(String message) {
		if (userinfocallback != null) {
			userinfocallback.getUserInfoCheck(message);
		}
	}

	public void setUserInfoCheck(userInfoCheck callbcak) {
		this.userinfocallback = callbcak;
	}

	public interface userInfoCheck {
		public void getUserInfoCheck(String message);
	}

	/**
	 * 上传百度推送ID
	 */
	public void upBaiDuPussh() {
		channelId = JPushInterface.getRegistrationID(getApplicationContext());
		if (userId == null) {
			return;
		}

		HttpJsonTool httpJsonTool = new HttpJsonTool(getApplicationContext());
		HashMap<String, Object> dataMap = new HashMap<String, Object>();
		L.v("upBaiDuPussh", "upBaiDuPussh");
		dataMap.put("channelId", channelId);
		// dataMap.put("", value);
		dataMap.put("userId", messagepushuserId);
		dataMap.put("carownerId", userId);
		dataMap.put("longitude", longitude+"");
		dataMap.put("latitude", latitude+"");
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
			}
		});
		httpJsonTool.StartWork(dataMap, GagApi.UP_BAIDU_CHANCEID, null, null);
	}

	/**
	 * 登录放在这里需要考虑但是时间不够 重构时候需要更改 这里是因为
	 */
	// 自动登录
	public void AntLogin() {
		String username = (String) SPUtils.get(this, "phone", "");
		String password = (String) SPUtils.get(this, "password", "");
		password = Base64Util.fromHex(password);
		if (username.isEmpty() || password.isEmpty()) {
			// 没有保存过的登录的信息

		} else {
			HashMap<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put("phone", username);
			dataMap.put("password", password);
			Login(dataMap);
		}
	}

	private void Login(final Map<String, Object> dataMap) {
		new ArrayList<LoginUserInfo>();
		Type type = new TypeToken<List<UserInfoBeen>>() {
		}.getType();
		// SeaveUserInfo(dataMap);
		HttpJsonTool httpJsonTool = new HttpJsonTool(this);
		httpJsonTool.SetOnLister(new Handler() {
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what == 1) {
					// app.userInfoBeen
					List<UserInfoBeen> d = (List<UserInfoBeen>) msg.obj;
					userInfoBeen = d.get(0);
					userId = d.get(0).getCarownerid() + "";
				}
			}
		});
		httpJsonTool.StartWork(dataMap, GagApi.LOGIN, type, null);
	}
}